package com.download.zhuaba.Controller;

import com.alibaba.fastjson.JSON;
import com.download.zhuaba.Entity.Music;
import com.download.zhuaba.Service.MusicService;
import com.download.zhuaba.Service.WelcomeService;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;

@Controller
public class MusicController {
    @GetMapping("/Music.html")
    public String music(Model model, HttpServletRequest request, HttpSession session) throws IOException {
        if(request.getSession().getAttribute("loginUser")!=null){
            ArrayList<Music> musics = MusicService.getMusic();
            String jsonList = JSON.toJSONString(musics);
            model.addAttribute("Musics",jsonList);
            session.setAttribute("flag", "1");//跳转地址不带上u2参数
            session.setAttribute("login","1");
            return "Music";
        }
        else{
            session.setAttribute("flag", "1");//跳转地址不带上u2参数
            session.setAttribute("login","0");
            return "login";
        }
    }
}

